﻿Imports ClaimsModel.Model

Namespace Services


    ''' <summary>
    ''' Updates all claims epalithefsi amounts
    ''' </summary>
    ''' <remarks></remarks>
    Public Class UpdateClaimAmountsService
        Private _ClaimsToProcess As List(Of Claim)

        Private ReadOnly Property ClaimsToProcess() As List(Of Claim)
            Get

                If _ClaimsToProcess Is Nothing Then

                    Dim whereC = <sql>
s_n in (select distinct s_n from claims where
isnull(KAT_PERC_1,0)+isnull(KAT_PERC_2,0)+isnull(KAT_PERC_3,0)+
        isnull(KAT_PERC_4,0)+isnull(KAT_PERC_5,0) +
isnull(CO_PERC_1,0)+isnull(CO_PERC_2,0)+isnull(CO_PERC_3,0)+
    isnull(CO_PERC_4,0)+isnull(CO_PERC_5,0)&gt;0)
                    </sql>


                    _ClaimsToProcess = ClaimDataUtils.findList(whereC.Value)

                End If
                Return _ClaimsToProcess
            End Get
        End Property

        Public Sub updateAmounts()

            Dim claimsList As List(Of Claim) = Me.ClaimsToProcess

            Try
                ModelContext.beginTrans()

                For Each cl As Claim In claimsList
                    cl.calculateAndsetAmounts()
                    Call ClaimDataUtils.saveClaim(cl)
                Next
                ModelContext.commitTrans()
            Finally
                ModelContext.rollbackTrans()
            End Try
        End Sub

    End Class

End Namespace